import * as constants from './constants';
import { fromJS } from 'immutable';
import { Conf } from '../../../utils';

const defaultState=fromJS({
    list:[],
    loading:true,
    total:0,
    emptyText:'暂无数据',
    page:1,
    pageSize:Conf.page_Conf.pageSize,
    formData:{
        arr:['name','type','width','height','description']
        ,name:{type:'input',title:'广告位名称',name:'name',autoFocus:true,placeholder:"请输入广告位名称",rules:[{
            required: true,
            whitespace: true,
            message: '广告位名称不能为空'
        }]}
        ,type:{type:'select',title:'广告类型',name:'type',options:[
            {name:"图片",value:"banner"}
            ,{name:"文字",value:"text"}
        ]}
        ,width:{type:'input.number',title:'宽度',min:0,name:'width'}
        ,height:{type:'input.number',title:'高度',min:0,name:'height'}
        ,description:{type:'text',title:'描述',rows:4,name:'description'}
    }
});
export default (state=defaultState,action)=>{
    switch (action.type) {
        case constants.LIST:
            return state.merge({
                list : fromJS(action.list),
                total : action.total
            })
        case constants.LOADING:
            return state.merge({
                loading : action.loading
            })
        case constants.NOAUTH:
            return state.merge({
                emptyText : action.emptyText
            })
            
        case constants.PAGESIZE:
            return state.merge({
                pageSize : action.pageSize
            })
        case constants.PAGE:
            return state.merge({
                page : action.page
            })
        default:
            break;
    }
    return state;
}